package com.sharp.authorization.dao.common.repository;

import com.sharp.authorization.dao.common.entity.SaArea;
import com.sharp.authorization.dao.common.mapper.SaAreaDao;
import com.sharp.kernel.mybatis.repository.BaseMysqlRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * Title: SaAreaService
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2022/6/16 16:20
 */
@Service
public class SaAreaService extends BaseMysqlRepository<SaArea, SaAreaDao> {

    @Resource
    private SaAreaDao saAreaDao;

    public List<SaArea> getAreaInfoByParentCode(String parentCode) {
        Example example = super.getExample();
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isBlank(parentCode)) {
            criteria.andIsNull("parentCode");
        } else {
            criteria.andEqualTo("parentCode", parentCode);
        }
        return super.select(example);
    }

    public void truncate() {
        saAreaDao.truncate();
    }

}
